#include "testDrive.h"

void constructorParser(string *arr, int line){
	big_number *a = NULL, *b = NULL;
	string className;
	bool exep=false;
	ostringstream oss;
	
	try {		
		exep = arr[2].compare("1") == 0;
		
		if (arr[0].compare("n") == 0)
		{
			className = "big_number";
			a = new big_number(arr[1]);
		}

		if (arr[0].compare("i") == 0)
		{
			className = "big_integer";
			a = new big_integer(arr[1]);
		}

		if (arr[0].compare("short") == 0)
		{
			short num;
			istringstream ( arr[1] ) >> num;
			className = "short";
			a = new big_number(num);
			b = new big_integer(num);
		}

		if (arr[0].compare("char") == 0)
		{
			char num;
			istringstream ( arr[1] ) >> num;
			className = "char";
			a = new big_number(num);
			b = new big_integer(num);
		}

		if (arr[0].compare("int") == 0)
		{
			int num;
			istringstream ( arr[1] ) >> num;
			className = "int";
			a = new big_number(num);
			b = new big_integer(num);
		}

		if (arr[0].compare("long") == 0)
		{
			long num;
			istringstream ( arr[1] ) >> num;
			className = "long";
			a = new big_number(num);
			b = new big_integer(num);
		}

		if (arr[0].compare("long long") == 0)
		{
			long long num;
			istringstream ( arr[1] ) >> num;
			className = "long long";
			a = new big_number(num);
			b = new big_integer(num);
		}

		if (arr[0].compare("unsigned char") == 0)
		{
			unsigned char num;
			istringstream ( arr[1] ) >> num;
			className = "unsigned char";
			a = new big_number(num);
			b = new big_integer(num);
		}

		if (arr[0].compare("unsigned short") == 0)
		{
			unsigned short num;
			istringstream ( arr[1] ) >> num;
			className = "unsigned short";
			a = new big_number(num);
			b = new big_integer(num);
		}

		if (arr[0].compare("unsigned int") == 0)
		{
			unsigned int num;
			istringstream ( arr[1] ) >> num;
			className = "unsigned int";
			a = new big_number(num);
			b = new big_integer(num);
		}

		if (arr[0].compare("unsigned long") == 0)
		{
			unsigned long num;
			istringstream ( arr[1] ) >> num;
			className = "unsigned long";
			a = new big_number(num);
			b = new big_integer(num);
		}

		if (arr[0].compare("unsigned long long") == 0)
		{
			unsigned long long num;
			istringstream ( arr[1] ) >> num;
			className = "unsigned long long";
			a = new big_number(num);
			b = new big_integer(num);
		}

		if (arr[0].compare("float") == 0)
		{
			float num;
			istringstream ( arr[1] ) >> num;
			className = "float";
			a = new big_number(num);
		}

		if (arr[0].compare("double") == 0)
		{
			double num;
			istringstream ( arr[1] ) >> num;
			className = "double";
			a = new big_number(num);
		}

		if (arr[0].compare("long double") == 0)
		{
			long double num;
			istringstream ( arr[1] ) >> num;
			className = "long double";
			a = new big_number(num);
		}

		oss << className << ":\t" << arr[1];
		if (!exep)
			logger::success(oss.str(), "ConstructorTest.txt", line);
		else
			logger::fail(oss.str(), "ConstructorTest.txt", line);
		if (a != NULL)
			free(a);

		if (b != NULL)
			free(b);
		
	}
	catch (...){
		oss << className << ":\t" << arr[1];
		if (exep){
			logger::success(oss.str(), "ConstructorTest.txt", line);
		}
		else{
			logger::fail(oss.str(), "ConstructorTest.txt", line);
		}
	}
}

void constructorTest(){
	PNode tmp, ptr = readFile("ConstructorTest.txt");
	string arr[3];
	printf("Start Constructors test \n");
	while (ptr != NULL){
		try {
			splitByComma(arr, ptr->line);
			constructorParser(arr, ptr->lineNumber);
		}
		catch (const std::exception &e) {
			cout << e.what() << endl;
			logger::exception(ptr->line, "ConstructorTest.txt", ptr->lineNumber);
		}
		tmp = ptr;
		ptr = ptr->next;
		freeNode(tmp);
	}
}